import {category} from '../../utils/interface'
Page({ 
  data: {
    activeKey: 0,
    allCatelist:[],
    oneCatelist:[],
    leftCatelist:[]
  },
  //跳转商品列表
  nextCatelist(e){
    let {id} = e.currentTarget
    wx.navigateTo({
      url: '/pages/catelist/catelist?cid='+id,
    })
  },
  onLoad(){
    this.getCategory()
  },
  async getCategory(){
    let {data:res} = await category()
    // console.log(res);
    let arr = res.data.filter(item => {
      return item.pid == 0
    })
    this.setData({
      allCatelist:res.data,
      oneCatelist:res.data,
      leftCatelist:arr
    })
  },
  // 切换分类
  changeCate(e){
    // console.log(e);
    let {id} = e.currentTarget
    if(id == 'all'){
      this.setData({
        oneCatelist:this.data.allCatelist
      })
    }else{
      let newArr = this.data.allCatelist.filter(item =>{
        return item.pid==id
      })
      this.setData({
        oneCatelist:newArr
      })
    }
  },
});
